home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / General / Open Prolog / External Predicates… / Sources / OpenPrologSpeech.p < prev    next >
Text File  |  1993-11-30  |  4KB  |  129 lines

  1. {$D+} { MacsBug symbols on }
  2. {$R+} { No range checking }
  3.  
  4. UNIT OpenPrologSpeech;
  5.  
  6.   INTERFACE
  7.  
  8.     USES memtypes, quickdraw, osintf, toolintf, standardFile, prlxdefinitions,
  9.          prlxLibraries, traps, gestaltEqu, speech;
  10.  
  11.     PROCEDURE entrypoint(plist: prlxptr);
  12.  
  13.   IMPLEMENTATION
  14.  
  15.      PROCEDURE main(plist: prlxptr);
  16.       FORWARD;
  17.  
  18.     PROCEDURE entrypoint(plist: prlxptr);
  19.  
  20.       BEGIN
  21.         main(plist);
  22.       END;
  23.  
  24.     FUNCTION speechManagerAvailable: osErr;
  25.  
  26.       VAR
  27.         result: longint;
  28.         err: osErr;
  29.  
  30.       BEGIN
  31.         speechManagerAvailable := noSynthFound;
  32.         {check for gestalt first}
  33.         IF TrapAvailable(_gestalt, ToolTrap)
  34.           THEN
  35.             BEGIN
  36.             err := gestalt(gestaltSpeechAttr, result);
  37.             IF err = noErr
  38.               THEN
  39.                 IF (bitAnd(result, 1 {is 1<<gestaltSpeechMgrPresent} ) <> 0)
  40.                   THEN speechManagerAvailable := noErr;
  41.             END;
  42.       END;
  43.  
  44.     PROCEDURE main;
  45.  
  46.       PROCEDURE checkOSErr(hostErrorCode: osErr; errorKind,
  47.                            argumentIndex: longint; s: str255);
  48.  
  49.         BEGIN
  50.           IF hostErrorCode <> noErr
  51.             THEN 
  52.                         begin
  53.                         signalError(errorKind, argumentIndex, hostErrorCode, s, plist);
  54.                         exit(main);
  55.                         end;
  56.         END;
  57.  
  58.       BEGIN
  59.         WITH plist^ DO
  60.           BEGIN
  61.           outcome := noErrorSucceed;
  62.           determinate := true;
  63.           CASE request OF
  64.             getPRLXInfo:
  65.               BEGIN
  66.               data[1] := 2; {number of predicates defined}
  67.               data[2] := eventsVersion;
  68.               data[3] := 0
  69.               END;
  70.             initialisepredicate:
  71.               CASE id OF
  72.                 1:
  73.                   BEGIN
  74.                   s := 'speakAtom'; {name}
  75.                   data[1] := 1; {arity}
  76.                   END;
  77.                 2:
  78.                   BEGIN
  79.                   s := 'speechBusy'; {name}
  80.                   data[1] := 1; {arity}
  81.                   END;
  82.                 OTHERWISE
  83.                   signalError(implementationError, - 1, 0,
  84.                               'predicate index out of range at initialise',
  85.                               plist);
  86.               END;
  87.             callpredicate:
  88.               BEGIN
  89.               WITH plist^ DO
  90.                 checkOSErr(speechManagerAvailable, implementationError, 0,
  91.                            'Speech Manager not Available');
  92.               CASE id OF
  93.                 1:
  94.                   WITH plist^ DO
  95.                     BEGIN
  96.                     WHILE speechBusy <> 0 DO;
  97.                     checkOSErr(speakString(text(1, plist)), implementationError,
  98.                                1, 'Error speaking this atom');
  99.                     END;
  100.                 2:
  101.                   WITH plist^ DO
  102.                     IF NOT returnValue(1, speechBusy, plist)
  103.                       THEN outcome := noErrorFail;
  104.                 OTHERWISE
  105.                   signalError(implementationError, - 1, 0,
  106.                               'predicate index out of range at callPredicate',
  107.                               plist);
  108.               END;
  109.               END;
  110.             closepredicate:
  111.               BEGIN
  112.               CASE id OF
  113.                 1: ;
  114.                 2: ;
  115.                 OTHERWISE
  116.                   signalError(implementationError, - 1, 0,
  117.                               'predicate index out of range at closePredicate',
  118.                               plist);
  119.               END;
  120.               END;
  121.             OTHERWISE
  122.               signalError(implementationError, - 1, 0,
  123.                      'unknown call to OpenPrologSpeech external predicate suite'
  124.                           , plist);
  125.           END;
  126.           END;
  127.       END;
  128. END.
  129.